using System;
using System.Windows.Forms;
using CodePlex.DnD4eCampaignManager.Presentation.PresenterInterfaces;
using CodePlex.DnD4eCampaignManager.Presentation.ViewInterfaces;

namespace CodePlex.DnD4eCampaignManager.ControlLibrary
{
    public partial class HealthControl : UserControl, IHealthView
    {
        private IHealthPresenter _presenter;

        public HealthControl()
        {
            InitializeComponent();
        }

        public int CurrentHealingSurges
        {
            get { return Convert.ToInt32(CurrentHealingSurgesTextbox.Value); }
            set { CurrentHealingSurgesTextbox.Value = value; }
        }

        public int CurrentHitPoints
        {
            get { return Convert.ToInt32(CurrentHitPointsTextbox.Value); }
            set { CurrentHitPointsTextbox.Value = value; }
        }

        public int HealingSurges
        {
            get { return Convert.ToInt32(HealingSurgesTextbox.Value); }
            set { HealingSurgesTextbox.Value = value; }
        }

        public int HealingSurgeValue
        {
            get { return Convert.ToInt32(HealingSurgeValueTextbox.Value); }
            set { HealingSurgeValueTextbox.Value = value; }
        }

        public int HitPointChangeValue { get; private set; }

        public int HitPoints
        {
            get { return Convert.ToInt32(HitPointsTextbox.Value); }
            set { HitPointsTextbox.Value = value; }
        }

        public IHealthPresenter Presenter
        {
            private get
            {
                if ( _presenter == null )
                {
                    throw new InvalidOperationException("The Presenter cannot be used before it is initialized.");
                }
                return _presenter;
            }
            set { _presenter = value; }
        }

        public int TemporaryHitPoints
        {
            get { return Convert.ToInt32(TemporaryHitPointsTextbox.Value); }
            set { TemporaryHitPointsTextbox.Value = value; }
        }

        private void DamageCombatant_Click(object sender, EventArgs e)
        {
            HitPointChangeValue = Convert.ToInt32(ModalNumberPicker.GetNumber("Damage", "Enter the number of Hit Points of damage:", 0, 250, 0, 318));
            Presenter.DamageCombatant();
        }

        private void HealCombatant_Click(object sender, EventArgs e)
        {
            HitPointChangeValue = Convert.ToInt32(ModalNumberPicker.GetNumber("Heal", "Enter the number of Hit Points of healing:", 0, 250, 0, 314));
            Presenter.HealCombatant();
        }

        private void SpendHealingSurge_Click(object sender, EventArgs e)
        {
            Presenter.SpendHealingSurge();
        }
    }
}